<template>
  <!--上传文件-->
  <div class="up">
    <div class="up-return">
      <el-button plain icon="el-icon-back" type="text" @click="returnTo()">返回</el-button>
    </div>

    <el-upload class="upload-demo" ref="upload" :action="fileAction" multiple :with-credentials="true"
         :file-list="fileList" :auto-upload="false" name="files">
      <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
      <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
    </el-upload>

    <div class="up-power">
      © 2021 Powered by zsc ccying
    </div>
  </div>
</template>

<style>
  .up {
    margin: auto;
    width: 40%;
  }
  .up-return {
    padding-right: 600px;
  }
  .up-power {
    padding-top: 100px;
  }
</style>

<script>
export default {
  data() {
    return {
      filename: '',
      fileAction: this.$http.defaults.baseURL + "file/up",
      fileList: []
    };
  },
  methods: {
    returnTo() {
      this.$router.go(-1);
    },
    submitUpload() {
      this.$refs.upload.submit();
    },
  },
  created() {
    this.$http({
      method: 'get',
      url: '/verify'
    }).then(res=>{
      let {code:code} = res.data;
      if (code === 1000) {
        //未登录
        this.$router.push('/');
      }
    })
  }
}
</script>
